<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <th:block th:include="include :: header('电机监控列表')" />
</head>
<body class="pear-container">
     <div class="layui-card">
        <div class="layui-card-body">
            <div class="col-sm-12 search-collapse">
                <form id="formId" class="layui-form">

                    <div class="layui-form-item">
                            <label class="layui-form-label">位置：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="motorPlace" placeholder="请输入位置" class="layui-input" />
                        </div>
                       
                        <label class="layui-form-label">型号：</label>
                        <div class="layui-input-inline">
                            <select name="motorType"   dict-code="input" >
                                <option value="">所有</option>
                            </select>
                        </div>
                            <label class="layui-form-label">图片：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="motorPrc" placeholder="请输入图片" class="layui-input" />
                        </div>
                                <label class="layui-form-label">转速：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="motorSpeed" placeholder="请输入转速" class="layui-input" />
                        </div>
                                <label class="layui-form-label">扭矩：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="motorTorque" placeholder="请输入扭矩" class="layui-input" />
                        </div>
                                <label class="layui-form-label">电流：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="motorCurrent" placeholder="请输入电流" class="layui-input" />
                        </div>
                                <label class="layui-form-label">电压：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="motorVoltage" placeholder="请输入电压" class="layui-input" />
                        </div>
                                <label class="layui-form-label">功率：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="motorPower" placeholder="请输入功率" class="layui-input" />
                        </div>
                                <label class="layui-form-label">厂家：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="manufacturer" placeholder="请输入厂家" class="layui-input" />
                        </div>
                                <label class="layui-form-label">售后电话：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="manufacturerPhone" placeholder="请输入售后电话" class="layui-input" />
                        </div>
                                <label class="layui-form-label">保修期：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="warrantyPeriod" placeholder="请输入保修期" class="layui-input" />
                        </div>
                                <label class="layui-form-label">电机对应的主轴：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="mototrAxis" placeholder="请输入电机对应的主轴" class="layui-input" />
                        </div>
                                <label class="layui-form-label">电机对应的刀具：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="motorTool" placeholder="请输入电机对应的刀具" class="layui-input" />
                        </div>
                                        <label class="layui-form-label">null：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="spare1" placeholder="请输入null" class="layui-input" />
                        </div>
                                <label class="layui-form-label">null：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="spare2" placeholder="请输入null" class="layui-input" />
                        </div>
                                <label class="layui-form-label">null：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="spare3" placeholder="请输入null" class="layui-input" />
                        </div>
                                <label class="layui-form-label">null：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="spare4" placeholder="请输入null" class="layui-input" />
                        </div>
                                <label class="layui-form-label">null：</label>
                        <div class="layui-input-inline">
                            <input type="text" name="spare5" placeholder="请输入null" class="layui-input" />
                        </div>
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="motor-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                    </div>
                </form>
            </div>
        </div>
     </div>
         <div class="layui-card">
             <div class="layui-card-body">
                 <table id="motor-table" lay-filter="motor-table"></table>

                 <script type="text/html" id="motor-toolbar">
                     <button  sec:authorize="hasPermission('/system/motor/add','system:motor:add')"  class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
                         <i class="layui-icon layui-icon-add-1"></i>
                         新增
                     </button>
                     <button  sec:authorize="hasPermission('/system/motor/remove','system:motor:remove')"   class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
                         <i class="layui-icon layui-icon-delete"></i>
                         删除
                     </button>
                 </script>

                 <script type="text/html" id="motor-bar">
                     <button  sec:authorize="hasPermission('/system/motor/edit','system:motor:edit')"   class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>
                     </button>
                     <button  sec:authorize="hasPermission('/system/motor/remove','system:motor:remove')"   class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i>
                     </button>
                 </script>
             </div>
         </div>
    <th:block th:include="include :: footer" />
         <script>
             layui.use(['table', 'form', 'jquery','dictionary'], function () {
                 let table = layui.table;
                 let form = layui.form;
                 let $ = layui.jquery;

                 let prefix = "/system/motor/";

                 let cols = [
                     [
                         {type: 'checkbox'},
                         {
                             field: 'motorId',
                             title: '电机id'
                         },
                        {
                             field: 'motorPlace',
                             title: '位置'
                        },
                        {
                             field: 'motorType',
                             title: '型号'
                        },
                        {
                             field: 'motorPrc',
                             title: '图片'
                        },
                        {
                             field: 'motorSpeed',
                             title: '转速'
                        },
                        {
                             field: 'motorTorque',
                             title: '扭矩'
                        },
                        {
                             field: 'motorCurrent',
                             title: '电流'
                        },
                        {
                             field: 'motorVoltage',
                             title: '电压'
                        },
                        {
                             field: 'motorPower',
                             title: '功率'
                        },
                        {
                             field: 'manufacturer',
                             title: '厂家'
                        },
                        {
                             field: 'manufacturerPhone',
                             title: '售后电话'
                        },
                        {
                             field: 'warrantyPeriod',
                             title: '保修期'
                        },
                        {
                             field: 'mototrAxis',
                             title: '电机对应的主轴'
                        },
                        {
                             field: 'motorTool',
                             title: '电机对应的刀具'
                        },
                        {
                             field: 'updatTime',
                             title: '修改日期'
                        },
                        {
                             field: 'creatTime',
                             title: '创建日期'
                        },
                        {
                             field: 'spare1',
                             title: 'null'
                        },
                        {
                             field: 'spare2',
                             title: 'null'
                        },
                        {
                             field: 'spare3',
                             title: 'null'
                        },
                        {
                             field: 'spare4',
                             title: 'null'
                        },
                        {
                             field: 'spare5',
                             title: 'null'
                        },
                         {title: '操作', toolbar: '#motor-bar', align: 'center', width: 130}
                     ]
                 ]

                 table.render({
                     elem: '#motor-table',
                     url: prefix + 'data',
                     page: true,
                     cols: cols,
                     skin: 'line',
                     toolbar: '#motor-toolbar',
                     defaultToolbar: [{
                         layEvent: 'refresh',
                         icon: 'layui-icon-refresh',
                     }, 'filter', 'print', 'exports']
                 });

                 table.on('tool(motor-table)', function (obj) {
                     if (obj.event === 'remove') {
                         window.remove(obj);
                     } else if (obj.event === 'edit') {
                         window.edit(obj);
                     }
                 });

                 table.on('toolbar(motor-table)', function (obj) {
                     if (obj.event === 'add') {
                         window.add();
                     } else if (obj.event === 'refresh') {
                         window.refresh();
                     } else if (obj.event === 'batchRemove') {
                         window.batchRemove(obj);
                     }
                 });

                 form.on('submit(motor-query)', function (data) {
                     table.reload('motor-table', {where: data.field})
                     return false;
                 });

                 window.add = function () {
                     layer.open({
                         type: 2,
                         title: '新增电机监控',
                         shade: 0.1,
                         area: ['550px', '500px'],
                         content: prefix + 'add'
                     });
                 }

                 window.edit = function (obj) {
                     layer.open({
                         type: 2,
                         title: '修改电机监控',
                         shade: 0.1,
                         area: ['550px', '500px'],
                         content: prefix + 'edit?motorId=' + obj.data['motorId']
                     });
                 }

                 window.remove = function (obj) {
                     layer.confirm('确定要删除该电机监控', {icon: 3, title: '提示'}, function (index) {
                         layer.close(index);
                         let loading = layer.load();
                         $.ajax({
                             url: prefix + "remove/" + obj.data['motorId'],
                             dataType: 'json',
                             type: 'delete',
                             success: function (result) {
                                 layer.close(loading);
                                 if (result.success) {
                                     layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                         obj.del();
                                     });
                                 } else {
                                     layer.msg(result.msg, {icon: 2, time: 1000});
                                 }
                             }
                         })
                     });
                 }

                 window.batchRemove = function (obj) {
                     let data = table.checkStatus(obj.config.id).data;
                     if (data.length === 0) {
                         layer.msg("未选中数据", {icon: 3, time: 1000});
                         return false;
                     }
                     let ids = "";
                     for (let i = 0; i < data.length; i++) {
                         ids += data[i].motorId + ",";
                     }
                     ids = ids.substr(0, ids.length - 1);
                     layer.confirm('确定要删除这些电机监控', {icon: 3, title: '提示'}, function (index) {
                         layer.close(index);
                         let loading = layer.load();
                         $.ajax({
                             url: prefix + "batchRemove",
                             dataType: 'json',
                             data: {"ids":ids},
                             type: 'delete',
                             success: function (result) {
                                 layer.close(loading);
                                 if (result.success) {
                                     layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                         table.reload('motor-table');
                                     });
                                 } else {
                                     layer.msg(result.msg, {icon: 2, time: 1000});
                                 }
                             }
                         })
                     });
                 }

                 window.refresh = function (param) {
                     table.reload('motor-table', {where: param});
                 }
             })
         </script>
</body>
</html>